package net.my.msn.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;

/**
 * class, which is the domain object of voice.
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAllVoices", query = "SELECT v FROM Voice v"),
		@NamedQuery(name = "isUserVotedForThisMessage", query = "SELECT COUNT(v) FROM Voice v WHERE v.message.messageId= :m_id "
				+ "AND v.user.userId= :u_id"),
		@NamedQuery(name = "findVoiceByMessageId", query = "SELECT COUNT(v) FROM Voice v WHERE v.message.messageId= :m_id") })
@Table(name = "voice")
public class Voice {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "voice_id")
	private Long voiceId;

	@ManyToOne(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id")
	private User user;

	@ManyToOne(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinColumn(name = "message_id")
	private Message message;

	public Long getVoiceId() {
		return voiceId;
	}

	public void setVoiceId(Long voiceId) {
		this.voiceId = voiceId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

}
